#pragma once
#include "noncopyable.h"
#include "eventloop.h"
#include "inet_address.h"
#include "socket.h"
#include "channel.h"
#include <atomic>
class Acceptor : noncopyable{
public:
    using NewConnectionCallBack = std::function<void(int sockfd, const InetAddress&)>;

    Acceptor(EventLoop* loop, const InetAddress& listenAddr, bool reuseport);
    ~Acceptor();

    void setNewConnectionCallBack(const NewConnectionCallBack& cb){
        newConnectionCallBack_ = cb;
    }

    bool listenning() const {return listenning_;}
    void listen();
private:
void handleRead();

    EventLoop* loop_;
    Socket acceptSocket_;
    Channel acceptChannel_;
    NewConnectionCallBack newConnectionCallBack_;
    bool listenning_;
};